package com.financing.wap.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.financing.wap.util.Constants;

import org.apache.commons.lang.StringUtils;

public class CommonConstantUtil {
	
	public static final String DATE_SIMU="2050-03-03";
	/**返利为百分比 */
	public static final String REBATE_RATIO = "01";
	/** 返利为金额 */
	public static final String REBATE_AMOUNT = "02";
	
	/**手动添加客户 */
	public static final String HAND_ADD_CLIENT = "2";
	/**微信来源添加客户*/
	public static final String WECHAT_ADD_CLIENT = "1";
	
	//店铺默认头像
	public static String DEFUALTIMAGE = "/upload/faUser/image/1.png";
	
	public static Map<String, String> tradeMap = null;
	public static Map<String, String> certTypeMap = null;
	//基金分类：1:股票型 2多空仓型3管理期货4市场中性5套利型6宏观策略7债券型8货币型9定向增发10多策略11其他12组合型13海外基金
	public static Map<String,String> jjflDesc= null;
	static{
		tradeMap = new HashMap<String, String>();
		tradeMap.put("01", "基金");
		tradeMap.put("02", "证劵");
		tradeMap.put("03", "期货");
		tradeMap.put("04", "投资");
		tradeMap.put("05", "银行");
		tradeMap.put("06", "保险");
		tradeMap.put("07", "信托");
		tradeMap.put("08", "担保");
		tradeMap.put("09", "拍卖");
		tradeMap.put("10", "典当");
		tradeMap.put("11", "其他");
		
		certTypeMap = new HashMap<String, String>();
		certTypeMap.put("01", "证劵执业资格");
		certTypeMap.put("02", "基金执业资格");
		certTypeMap.put("03", "期货执业资格");
		certTypeMap.put("04", "黄金投资分析师职业资格");
		certTypeMap.put("05", "上海金交所交易员资格");
		certTypeMap.put("06", "理财规划师职业资格");
		certTypeMap.put("07", "保险咨询");
		certTypeMap.put("08", "港股投资咨询");
		certTypeMap.put("09", "美国证券期货执业资格");
		certTypeMap.put("10", "金融理财师职业资格");
		certTypeMap.put("11", "特许金融分析师资格");
		certTypeMap.put("12", "注册国际投资分析师资格");
		
		jjflDesc=new HashMap<String, String>();
		jjflDesc.put("1","股票型");
		jjflDesc.put("2","多空仓型");
		jjflDesc.put("3","管理期货");
		jjflDesc.put("4","市场中性");
		jjflDesc.put("5","套利型");
		jjflDesc.put("6","套利型");
		jjflDesc.put("7","债券型");
		jjflDesc.put("8","货币型");
		jjflDesc.put("9","定向增发");
		jjflDesc.put("10","多策略");
		jjflDesc.put("11","其他");
		jjflDesc.put("12","组合型");
		jjflDesc.put("13","海外基金");
	}
	
	/**
	 * 返利是否百分比
	 * @return
	 */
	public static Boolean isRatio(String rebateType) {
		return CommonConstantUtil.REBATE_RATIO.equals(rebateType); 
	}
	
	//TODO 枚举 
	/**
	 * 获得投资行业
	 * @param investType
	 * @return
	 */
	public static String getInvestDesc(String investType){
		if("01".equals(investType)){
			return "房地产类";
		}else if("02".equals(investType)){
			return "金融市场";
		}else if("03".equals(investType)){
			return "基础设施";
		}else if("04".equals(investType)){
			return "其他";
		}else if("05".equals(investType)){
			return "城投债";
		}else if("06".equals(investType)){
			return "工商企业";
		}else if("07".equals(investType)){
			return "资金池";
		}
		return "其它";
	}
	
	public static String getProductTypeDesc(String ptype){
		if("01".equals(ptype)){
			return "基金";
		}else if("02".equals(ptype)){
			return "信托";
		}
		return "其它";
	}
	
	/**
	 * 销售状态
	 * @param status
	 * @return
	 */
	public static String getProductSaleStatusDesc(String status){
		if("01".equals(status)){
			return "未开始";
		}else if("02".equals(status)){
			return "预售中";
		}else if("03".equals(status)){
			return "募集中";
		}else if("04".equals(status)){
			return "已募满";
		}
		return "其它";
	}
	
	/**
	 * 付息方式
	 * @param status
	 * @return
	 */
	public static String getPaymentInterestTypeDesc(String status){
		if("01".equals(status)){
			return "按月付息";
		}else if("02".equals(status)){
			return "按季付息";
		}else if("03".equals(status)){
			return "按半年付息";
		}else if("04".equals(status)){
			return "按年付息";
		}else if("05".equals(status)){
			return "到期还本付息";
		}else if("06".equals(status)){
			return "按自然半年付息";
		}else if("07".equals(status)){
			return "按顺延半年付息";
		}else if("08".equals(status)){
			return "按自然季度付息";
		}else if("09".equals(status)){
			return "按顺延季度付息";
		}
		return "其它";
	}
	
//	/**
//	 * 申请预约
//	 */
//	public final static String STATUS_PRE_NEW = "010";
//	
//	/**
//	 * 已付定金
//	 */
//	public final static String STATUS_PRE_PAY = "020";
//	/**
//	 * 预约成功
//	 */
//	public final static String STATUS_PRE_OK = "030";
//	/**
//	 * 预约失败
//	 */
//	public final static String STATUS_PRE_FAIL = "040";
//
//	/**
//	 * 合同已寄出
//	 */
//	public final static String STATUS_HETONG_BEGIN = "110";
//	/**
//	 * 签单&打款
//	 */
//	public final static String STATUS_HETONG_ORDER = "120";
//
//	/**
//	 * 到款
//	 */
//	public final static String STATUS_HETONG_GET = "140";
//	/**
//	 * 生效
//	 */
//	public final static String STATUS_HETONG_OK = "150";
//
//	/**
//	 * 对账
//	 */
//	public final static String STATUS_REBATE_JIESUAN = "210";
//	
//	/**
//	 * 返佣
//	 */
//	public final static String STATUS_REBATE_GET = "220";
//	/**
//	 * 返佣确认
//	 */
//	public final static String STATUS_REBATE_SURE = "230";
//	/**
//	 * 评论
//	 */
//	public final static String STATUS_REBATE_DISCUSS = "240";
	
	/**
	 * 订单是否已预约
	 * @param orderStatus
	 * @return
	 */
	public static boolean isAppointmentOrder(Integer orderStatus){
		if(Constants.STATUS_PRE_OK.equals(orderStatus)
				||Constants.STATUS_HETONG_BEGIN.equals(orderStatus)
				||Constants.STATUS_HETONG_ORDER.equals(orderStatus)
				||isSigningOrder(orderStatus)
				){
			return true; 
		}
		return false;
	}
	
	/**
	 * 订单是否已签约
	 * @param orderStatus
	 * @return
	 */
	public static boolean isSigningOrder(Integer orderStatus){
		if(Constants.STATUS_HETONG_GET.equals(orderStatus)
				||Constants.STATUS_HETONG_OK.equals(orderStatus)
				||Constants.STATUS_REBATE_JIESUAN.equals(orderStatus)
				||Constants.STATUS_REBATE_GET.equals(orderStatus)
				||Constants.STATUS_REBATE_SURE.equals(orderStatus)
				||Constants.STATUS_REBATE_COMMENT.equals(orderStatus)
				){
		return true; //TODO
		}
		return false;
	}
	
	/**
	 * 返回状态字段
	 * @return
	 */
	public static List<Map<String,Object>> getStatusLable(){
		List<Map<String,Object>> l = new ArrayList<Map<String,Object>>();
		Map<String,Object> m010 = new HashMap<String,Object>();
		m010.put("code", Constants.STATUS_PRE_NEW);
		m010.put("value", "申请预约");
		l.add(m010);
		
		Map<String,Object> m020 = new HashMap<String,Object>();
		m020.put("code",Constants.STATUS_PRE_PAY);
		m020.put("value", "已付定金");
		l.add(m020);
		
		Map<String,Object> m021 = new HashMap<String,Object>();
		m021.put("code","121");
		m021.put("value", "申请预约");
		l.add(m021);
		
		Map<String,Object> m023 = new HashMap<String,Object>();
		m023.put("code","123");
		m023.put("value", "申请预约");
		l.add(m023);
		
		Map<String,Object> m024 = new HashMap<String,Object>();
		m024.put("code","124");
		m024.put("value", "申请预约");
		l.add(m024);
//		<option value="121">审核通过-含订金到账确认	</option>
//		<option value="123">向PP申请合同</option>
//		<option value="124">收到PP合同	</option>
		
		Map<String,Object> m030 = new HashMap<String,Object>();
		m030.put("code",Constants.STATUS_PRE_OK);
		m030.put("value", "预约成功");
		l.add(m030);
		
		Map<String,Object> m040 = new HashMap<String,Object>();
		m040.put("code",Constants.STATUS_PRE_FAIL);
		m040.put("value", "预约失败");
		l.add(m040);
		
		Map<String,Object> m110 = new HashMap<String,Object>();
		m110.put("code",Constants.STATUS_HETONG_BEGIN);
		m110.put("value", "合同已寄出");
		l.add(m110);
		
		Map<String,Object> m120 = new HashMap<String,Object>();
		m120.put("code",Constants.STATUS_HETONG_ORDER);
		m120.put("value", "签单&打款");
		l.add(m120);
		
		Map<String,Object> m140 = new HashMap<String,Object>();
		m140.put("code",Constants.STATUS_HETONG_GET);
		m140.put("value", "打款已到账");
		l.add(m140);
		
		Map<String,Object> m150 = new HashMap<String,Object>();
		m150.put("code",Constants.STATUS_HETONG_OK);
		m150.put("value", "产品已成立");
		l.add(m150);
		
		Map<String,Object> m210 = new HashMap<String,Object>();
		m210.put("code",Constants.STATUS_REBATE_JIESUAN);
		m210.put("value", "对账中");
		l.add(m210);
		
		Map<String,Object> m211 = new HashMap<String,Object>();
		m211.put("code","311");
		m211.put("value", "对账中");
		l.add(m211);
		
		Map<String,Object> m212 = new HashMap<String,Object>();
		m212.put("code","312");
		m212.put("value", "对账中");
		l.add(m212);
		
		Map<String,Object> m213 = new HashMap<String,Object>();
		m213.put("code","313");
		m213.put("value", "对账中");
		l.add(m213);
		
		Map<String,Object> m214 = new HashMap<String,Object>();
		m214.put("code","314");
		m214.put("value", "对账中");
		l.add(m214);
//		<option value="311">与PP结算中</option>		
//		<option value="312">与PP结算完成</option>	
//		<option value="313">与FA结算中</option>	
//		<option value="314">与FA结算完成</option>
		
		Map<String,Object> m220 = new HashMap<String,Object>();
		m220.put("code",Constants.STATUS_REBATE_GET);
		m220.put("value", "已返佣");
		l.add(m220);
		
		Map<String,Object> m230 = new HashMap<String,Object>();
		m230.put("code",Constants.STATUS_REBATE_SURE);
		m230.put("value", "佣金已到账");
		l.add(m230);
		
		Map<String,Object> m240 = new HashMap<String,Object>();
		m240.put("code",Constants.STATUS_REBATE_COMMENT);
		m240.put("value", "已评论");
		l.add(m240);
		
		Map<String,Object> m999 = new HashMap<String,Object>();
		m999.put("code","999");
		m999.put("value", "订单取消");
		l.add(m999);
		return l;
		
	}
//	P_DUE_TIME
	/**
	 * 产品期限计算，根据传入code返回期限天数
	 * dueTimeStart期限上限天数,dueTimeEnd期限下限天数
	 * @param dueTimeCode
	 * @return map,产品期限的上下区间
	 */
	public static Map<String,Object> dueTimeUtils(String dueTimeCode){



		StringBuffer strBuffer = new StringBuffer();

		int yearDay = 12;
		int dueTimeStart = 0;
		int dueTimeEnd = 0;
		String dueTimeStartKey = "dueTimeStart";
		String dueTimeEndKey = "dueTimeEnd";

		String dueTimeKey = "dueTimeQuery";

		Map<String,Object> dueTimeMap = new HashMap<String,Object>();

		if(StringUtils.isBlank(dueTimeCode)){
			return dueTimeMap;
		}

		if(dueTimeCode.indexOf("01") >=0){
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 0 and 6 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 0 and 6 ");
			}
			//6个月内

		}
		if(dueTimeCode.indexOf("02") >=0){
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 6 and 11 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 6 and 11 ");
			}
			//6-11个月
		}

		if(dueTimeCode.indexOf("03") >=0){

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME = 12 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME = 12 ");
			}
			//12个月
		}

		if(dueTimeCode.indexOf("04") >=0){

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME between 13 and 23 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME between 13 and 23 ");
			}
			// 13-23个月
		}

		if(dueTimeCode.indexOf("05") >=0){

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME = 24 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME = 24 ");
			}
			// 13-23个月
		}

		if(dueTimeCode.indexOf("06") >=0){

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" p.P_DUE_TIME >24 ");
			}else{
				strBuffer.append(" p.P_DUE_TIME >24");
			}
			//2年以上(含3年)
		}if(dueTimeCode.indexOf("07") >=0){
			//不限
		}
		dueTimeMap.put(dueTimeKey, strBuffer.toString());
		return dueTimeMap;
	}
//	P_ANNUAL_REVENUE_EIGHT_WITHIN
	/**
	 * 预期收益计算，根据传入code返回预期收益区间
	 * annualRevenueStart收益下限,annualRevenueEnd收益上限
	 * @param annualRevenueCode
	 * @return map,预期收益的上下区间
	 */
	public static Map<String,Object> annualRevenueUtils(String annualRevenueCode){
		StringBuffer strBuffer = new StringBuffer();

		String annualRevenueStartKey = "annualRevenueStart";
		String annualRevenueEndKey = "annualRevenueEnd";

		String annualRevenueKey = "annualRevenueKey";

		Map<String,Object> annualRevenueMap = new HashMap<String,Object>();

		if(StringUtils.isBlank(annualRevenueCode)){
			return  annualRevenueMap;
		}

		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_EIGHT_WITHIN) >=0){
			//7%以内
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 0 and 6.99 ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 0 and 6.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_EIGHT_TEN) >=0){
			//7-8%
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 7 and 7.99 ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 7 and 7.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_TEN_FIRTH) >=0){
			//8-9%

			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 8 and 8.99 ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 8 and 8.99 ");
			}
		}
		if(annualRevenueCode.indexOf(Constants.P_ANNUAL_REVENUE_FIRTH_MORE) >=0){
			//9-10%
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 9 and 9.99 ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT between 9 and 9.99 ");
			}
		}

		if(annualRevenueCode.indexOf("05") >=0){
			//10%以上
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT >= 10 ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT >= 10 ");
			}
		}

		if(annualRevenueCode.indexOf("06") >=0){
			//不限  浮动
			if(strBuffer.length() >0){
				strBuffer.append(" or ");
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT like '%浮动%' ");
			}else{
				strBuffer.append(" P_ANNUAL_REVENUE_EXPECT like '%浮动%' ");
			}
		}
		annualRevenueMap.put(annualRevenueKey, strBuffer.toString());

		return annualRevenueMap;
		
	}
}
